package com.cddx.logistics.controller;

import com.cddx.logistics.domain.dto.VehicleQueryDTO;
import com.cddx.logistics.domain.pojo.Vehicle;
import com.cddx.logistics.domain.vo.VehicleVO;
import com.cddx.logistics.service.VehicleService;
import com.cddx.logistics.util.model.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/vehicle")
@Api(tags = "车辆管理")
public class VehicleController {
    @Resource
    private VehicleService vehicleService;

    @GetMapping("/queryPage")
    @ApiOperation("分页查询车辆")
    public R queryPage(VehicleQueryDTO queryDTO) {
        PageInfo<VehicleVO> pageInfo = vehicleService.queryPage(queryDTO);
        return R.ok(pageInfo);
    }

    @PostMapping("/add")
    @ApiOperation("添加车辆")
    public R add(Vehicle vehicle) {
        return vehicleService.add(vehicle) ? R.ok("添加成功") : R.error("添加失败");
    }

    @PostMapping("/update")
    @ApiOperation("修改车辆信息")
    public R update(Vehicle vehicle) {
        return vehicleService.update(vehicle) ? R.ok("修改成功") : R.error("修改失败");
    }

    @GetMapping("/delete")
    @ApiOperation("删除车辆")
    public R delete(Integer id) {
        return vehicleService.delete(id) ? R.ok("删除成功") : R.error("删除失败");
    }

    @PostMapping("/batchDelete")
    @ApiOperation("批量删除车辆")
    public R batchDelete(@RequestBody List<Integer> ids) {
        return vehicleService.batchDelete(ids) ? R.ok("批量删除成功") : R.error("批量删除失败");
    }
}
